import store from '@/store'

/**
 * 校验权限字符串
 * 使用方法：import { checkPermi, checkRole } from "@/utils/permission";
 *         v-if="checkPermi(['system:user:add'])"
 *
 * @param {Array} value 校验值
 * @returns {boolean} 当前用户是否拥有此权限
 */
export function checkPermission(value) {
    if (value && value instanceof Array && value.length > 0) {
        const permissions = store.getters && store.getters.permissions
        const permissionDatas = value
        const all_permission = "*:*:*"

        return permissions.some(permission => {
            return all_permission === permission || permissionDatas.includes(permission)
        })
    } else {
        console.error(`需要权限! 示例: checkPermission="['system:user:add','system:user:edit']"`)
        return false
    }
}
